from django.http import HttpResponse
from amscms.dict.models import Term
from django.utils import simplejson

def suggest_term(request):
    if not request.is_ajax():
        return HttpResponse('Not AJAX Request', mimetype='text/plain')
    if not request.GET.get('term'):
        return HttpResponse('No "term" paramter', mimetype='text/plain')
    q = request.GET.get('term')
    terms = Term.objects.filter(term__contains=q)
    term_names = simplejson.dumps([t.term for t in terms], ensure_ascii=False)
    return HttpResponse(term_names, mimetype='text/json')
    

